//
//  FKInviteCodeVC.m
//  WanTao
//
//  Created by Macbook Pro on 2019/3/14.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKInviteCodeVC.h"
#import "FKWebViewVC.h"
#import "FKConfirmInviterVC.h"

@interface FKInviteCodeVC ()

@property (weak, nonatomic) IBOutlet UITextField *codeField;
@property (weak, nonatomic) IBOutlet UIButton *bindBtn;
@property (weak, nonatomic) IBOutlet UIButton *loginNowBtn;

@end

@implementation FKInviteCodeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"邀请码";
    [self.bindBtn setBackgroundImage:[UIImage imageNamed:@"bg_main"] forState:UIControlStateNormal];
    [self.bindBtn setBackgroundImage:[UIImage fk_imageWithColor:fkColor(204, 204, 204)] forState:UIControlStateDisabled];
    
    self.loginNowBtn.titleLabel.attributedText = [self.loginNowBtn.titleLabel.text fk_addAttributeStyle:@"无邀请码，" color:fkColor666666 font:[UIFont systemFontOfSize:12]];
}

- (IBAction)codeFieldValueChanged:(UITextField *)sender
{
    self.bindBtn.enabled = sender.text.length == 6;
}

- (IBAction)bindBtnClicked:(UIButton *)sender
{
    sender.enabled = false;
    FKConfirmInviterVC *vc = [[FKConfirmInviterVC alloc] init];
    vc.invite_code = self.codeField.text;
    fkPushNav(vc);
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    self.bindBtn.enabled = self.codeField.text.length == 6;
}

- (IBAction)agreementBtnClicked:(UIButton *)sender
{
    sender.enabled = false;
    [SVProgressHUD show];
    [FKHttpTool postWithSuffix:@"m=Home&c=Login&a=regProtocol" param:nil success:^(FKBaseResult *result) {
        sender.enabled = true;
        if (result.isSuccess) {
            [SVProgressHUD dismiss];
            NSDictionary *regProtocol = result.data[@"regProtocol"];
            FKWebViewVC *vc = [FKWebViewVC webVCWithPath:[NSURL URLWithString:regProtocol[@"url"]] title:@"用户协议"];
            fkPushNav(vc);
        }
    } failure:^(NSError *error) {
        sender.enabled = true;
    }];
}

- (IBAction)loginNowBtnClicked:(UIButton *)sender
{
    [FKLoginTool changeRootVC];
//    [self.navigationController dismissViewControllerAnimated:true completion:nil];
}

@end
